Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DefaultEndpointResolver to the orchestrator #2577

Merged
merged 8 commits into from
Apr 17, 2023

Conversation

ysaito1001
Copy link
Contributor

@ysaito1001 ysaito1001 commented Apr 13, 2023

Motivation and Context

This PR adds DefaultEndpointResolver, a default implementer of the EndpointResolver trait, to the orchestrator.

Description

Roughly speaking, the endpoint-related work is currently done by make_operation and SmithyEndpointStage, where make_operation constructs endpoint params and applies an endpoint resolver and the SmithyEndpointStage later updates the request header based on the resolved endpoint. In the orchestrator world, that work is handled by DefaultEndpointResolver::resolve_and_apply_endpoint.

The way endpoint parameters and an endpoint prefix are made available to DefaultEndpointResolver::resolve_and_apply_endpoint is done by interceptors because they may require pieces of information only available in an operation input struct. The place that has access to both an operation input struct and a config bag happens to be an interceptor.

There are two interceptors <Operation>EndpointParamsInterceptor and <Operation>EndpointParamsFinalizerInterceptor per operation. We pass around endpoint params builder through interceptors to allow it to be configured with more information at a later point; An end point parameters builder is first initialized within the ServiceRuntimePlugin with the field values obtained from the service config, and is stored in a config bag. The finalizer interceptor "seals" the builder and creates the actual endpoint params before it is passed to DefaultEndpointResolver::resolve_and_apply_endpoint. These interceptors implement read_before_execution because they need to access an operation input before it gets serialized (otherwise, context.input() would return a None).

Testing

Replaced StaticUriEndpointResolver with DefaultEndpointResolver in sra_test and verified the test continued passing.

UPDATE: The test currently fails in the main branch (it returns a None when extracting SigV4OperationSigningConfig from the config bag in OverrideSigningTimeInterceptor, hence unwrap fails), and by merging the main branch this PR no longer passes the test, but it does not add new failures either.


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

This commit adds `DefaultEndpointResolver` to the orchestrator. The type
implements the `EndpointResolver` trait and takes over the work previously
done by `make_operation` and `SmithyEndpointStage`.
This commit places `DefaultEndpointResolver` and endpoint params builder
in the config bag from within `ServiceRuntimePlugin`. Notice we put a
builder, not endpoint params, because full construction of endpoint
params requires additional values to be set from an operation input,
which will later be handled by an interceptor.
This commit generates interceptors for configuring endpoint params in the
orchestrator. There are two interceptors: one is to update params builder
with operation specific information, e.g. a bucket name, and the other is
to convert the params builder to the actual endpoint params by calling
`.build`.
This commit adds a codegen decorator to register interceptors to
`OperationRuntimePlugin`.
This commit replaces `StaticUriEndpointResolver` with
`DefaultEndpointResolver` in `sra_test` to ensure the test continues to
work end-to-end.
@github-actions
Copy link

A new generated diff is ready to view.

A new doc preview is ready to view.

This commit allows the `clippy::useless_conversion` only when
`enableNewSmithyRuntime` is true. When we stop rendering an endpoint
prefix in `make_operation` after completingly switching over to the
orchestrator world, we can remove the attribute.
@github-actions
Copy link

A new generated diff is ready to view.

A new doc preview is ready to view.

@ysaito1001 ysaito1001 added this pull request to the merge queue Apr 17, 2023
Merged via the queue into main with commit 7cb9d6a Apr 17, 2023
@ysaito1001 ysaito1001 deleted the ysaito/default-ep-resolver-in-orc branch April 17, 2023 21:25
Copy link
Collaborator

@jdisanti jdisanti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed this PR since I was out last week. I have some comments around errors.

Comment on lines +96 to +103
HeaderName::from_str(header_name).map_err(|err| {
ResolveEndpointError::message("invalid header name")
.with_source(Some(err.into()))
})?,
HeaderValue::from_str(value).map_err(|err| {
ResolveEndpointError::message("invalid header value")
.with_source(Some(err.into()))
})?,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these errors even be possible if the endpoint config is valid?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not entirely sure. I've decided to preserve the existing error handling logic from the original PR for the sake of porting. I don't see how an endpoint resolver comes into being after a series of config steps in the orchestrator world is all that different from the old world, so maybe it makes sense to keep the existing error handling for now (we can later turn them into non-recoverable errors, if we want).

ysaito1001 added a commit that referenced this pull request Apr 18, 2023
ysaito1001 added a commit that referenced this pull request Apr 18, 2023
ysaito1001 added a commit that referenced this pull request Apr 21, 2023
## Motivation and Context
This PR incorporates post-merge feedback left in #2577.

----

_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._

---------

Co-authored-by: Yuki Saito <awsaito@amazon.com>
ysaito1001 added a commit that referenced this pull request Apr 21, 2023
This commit ports fixes made in #2592, which addresses the following
#2577 (comment)
unexge pushed a commit that referenced this pull request Apr 24, 2023
## Motivation and Context
This PR adds `DefaultEndpointResolver`, a default implementer of the
[EndpointResolver](https://github.com/awslabs/smithy-rs/blob/1e27efe05fe7b991c9f9bbf3d63a297b2dded334/rust-runtime/aws-smithy-runtime-api/src/client/orchestrator.rs#L182-L184)
trait, to the orchestrator.

## Description
Roughly speaking, the endpoint-related work is currently done by
`make_operation` and `SmithyEndpointStage`, where `make_operation`
constructs endpoint params and applies an endpoint resolver and the
`SmithyEndpointStage` later updates the request header based on the
resolved endpoint. In the orchestrator world, that work is handled by
`DefaultEndpointResolver::resolve_and_apply_endpoint`.

The way endpoint parameters and an endpoint prefix are made available to
`DefaultEndpointResolver::resolve_and_apply_endpoint` is done by
interceptors because they _may_ require pieces of information only
available in an operation input struct. The place that has access to
both an operation input struct and a config bag happens to be an
interceptor.

There are two interceptors `<Operation>EndpointParamsInterceptor` and
`<Operation>EndpointParamsFinalizerInterceptor` per operation. We pass
around endpoint params _builder_ through interceptors to allow it to be
configured with more information at a later point; An end point
parameters builder is first initialized within the
`ServiceRuntimePlugin` with the field values obtained from the service
config, and is stored in a config bag. The finalizer interceptor "seals"
the builder and creates the actual endpoint params before it is passed
to `DefaultEndpointResolver::resolve_and_apply_endpoint`. These
interceptors implement `read_before_execution` because they need to
access an operation input before it gets serialized (otherwise,
`context.input()` would return a `None`).

## Testing
Replaced `StaticUriEndpointResolver` with `DefaultEndpointResolver` in
`sra_test` and verified the test continued passing.

UPDATE: The test currently fails in the `main` branch (it returns a
`None` when extracting `SigV4OperationSigningConfig` from the config bag
in `OverrideSigningTimeInterceptor`, hence `unwrap` fails), and by
merging the `main` branch this PR no longer passes the test, but it does
not add new failures either.

----

_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._

---------

Co-authored-by: Yuki Saito <awsaito@amazon.com>
unexge pushed a commit that referenced this pull request Apr 24, 2023
## Motivation and Context
This PR incorporates post-merge feedback left in #2577.

----

_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._

---------

Co-authored-by: Yuki Saito <awsaito@amazon.com>
rcoh pushed a commit that referenced this pull request Apr 24, 2023
## Motivation and Context
This PR adds `DefaultEndpointResolver`, a default implementer of the
[EndpointResolver](https://github.com/awslabs/smithy-rs/blob/1e27efe05fe7b991c9f9bbf3d63a297b2dded334/rust-runtime/aws-smithy-runtime-api/src/client/orchestrator.rs#L182-L184)
trait, to the orchestrator.

## Description
Roughly speaking, the endpoint-related work is currently done by
`make_operation` and `SmithyEndpointStage`, where `make_operation`
constructs endpoint params and applies an endpoint resolver and the
`SmithyEndpointStage` later updates the request header based on the
resolved endpoint. In the orchestrator world, that work is handled by
`DefaultEndpointResolver::resolve_and_apply_endpoint`.

The way endpoint parameters and an endpoint prefix are made available to
`DefaultEndpointResolver::resolve_and_apply_endpoint` is done by
interceptors because they _may_ require pieces of information only
available in an operation input struct. The place that has access to
both an operation input struct and a config bag happens to be an
interceptor.

There are two interceptors `<Operation>EndpointParamsInterceptor` and
`<Operation>EndpointParamsFinalizerInterceptor` per operation. We pass
around endpoint params _builder_ through interceptors to allow it to be
configured with more information at a later point; An end point
parameters builder is first initialized within the
`ServiceRuntimePlugin` with the field values obtained from the service
config, and is stored in a config bag. The finalizer interceptor "seals"
the builder and creates the actual endpoint params before it is passed
to `DefaultEndpointResolver::resolve_and_apply_endpoint`. These
interceptors implement `read_before_execution` because they need to
access an operation input before it gets serialized (otherwise,
`context.input()` would return a `None`).

## Testing
Replaced `StaticUriEndpointResolver` with `DefaultEndpointResolver` in
`sra_test` and verified the test continued passing.

UPDATE: The test currently fails in the `main` branch (it returns a
`None` when extracting `SigV4OperationSigningConfig` from the config bag
in `OverrideSigningTimeInterceptor`, hence `unwrap` fails), and by
merging the `main` branch this PR no longer passes the test, but it does
not add new failures either.

----

_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._

---------

Co-authored-by: Yuki Saito <awsaito@amazon.com>
rcoh pushed a commit that referenced this pull request Apr 24, 2023
## Motivation and Context
This PR incorporates post-merge feedback left in #2577.

----

_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._

---------

Co-authored-by: Yuki Saito <awsaito@amazon.com>
@rcoh rcoh mentioned this pull request Apr 25, 2023
1 task
unexge pushed a commit that referenced this pull request Apr 25, 2023
## Motivation and Context
- #2577 added a `Debug` bound on `ResolveEndpoint`, but this was a
semver-incompatible change

## Description
This removes that bound but re-adds a Debug implementation in areas that
we need them

## Testing
- CI

- [ ] Backport this commit to main

----

_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._
rcoh pushed a commit that referenced this pull request Apr 26, 2023
## Motivation and Context
Port #2630 to the `main`
branch.

## Description
Adding `Debug` bound on `ResolveEndpoint` in
#2577 was a breaking change.
Unfortunately, the semvar check that ran in that PR barked at a
different thing (i.e. barked at moving `StaticUriEndpointResolver` and
`DefaultEndpointResolver` from `aws-smithy-runtime-api` to
`aws-smithy-runtime`). Eventually the breaking change got merged to the
`main` branch.

This PR reverts the change in question and implements the `Debug` trait
for `ResolveEndpoint` in a semvar non-breaking way.

## Testing
- [ ] Passed tests in CI

----

_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._

Co-authored-by: Yuki Saito <awsaito@amazon.com>
david-perez pushed a commit that referenced this pull request May 18, 2023
Port #2630 to the `main`
branch.

Adding `Debug` bound on `ResolveEndpoint` in
#2577 was a breaking change.
Unfortunately, the semvar check that ran in that PR barked at a
different thing (i.e. barked at moving `StaticUriEndpointResolver` and
`DefaultEndpointResolver` from `aws-smithy-runtime-api` to
`aws-smithy-runtime`). Eventually the breaking change got merged to the
`main` branch.

This PR reverts the change in question and implements the `Debug` trait
for `ResolveEndpoint` in a semvar non-breaking way.

- [ ] Passed tests in CI

----

_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._

Co-authored-by: Yuki Saito <awsaito@amazon.com>
david-perez pushed a commit that referenced this pull request May 22, 2023
Port #2630 to the `main`
branch.

Adding `Debug` bound on `ResolveEndpoint` in
#2577 was a breaking change.
Unfortunately, the semvar check that ran in that PR barked at a
different thing (i.e. barked at moving `StaticUriEndpointResolver` and
`DefaultEndpointResolver` from `aws-smithy-runtime-api` to
`aws-smithy-runtime`). Eventually the breaking change got merged to the
`main` branch.

This PR reverts the change in question and implements the `Debug` trait
for `ResolveEndpoint` in a semvar non-breaking way.

- [ ] Passed tests in CI

----

_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._

Co-authored-by: Yuki Saito <awsaito@amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants